<?php
	defined('ALLOW') or die('Lỗi kết nối!');
    $Loi = false;
    $MaBaiViet = $_POST['MaBaiViet'];
    $TieuDeCu = $_POST['TieuDeCu'];
	$MaChuDe = $_POST['MaChuDe'];
	$TieuDe	= $_POST['TieuDe'];
	$TomTat	= $_POST['TomTat'];
	$NoiDung = $_POST['NoiDung'];
    $isset = 0;
    $baiviet = new baivietbs();
    $baiviet->TieuDe = $TieuDeCu;
    $baiviet->MaChuDe = $MaChuDe;
    $danhsach = $baiviet->GetListArticleNotIn();
    for($i = 0; $i < ($danhsach != false ? count($danhsach) : 0); $i++)
    {
        if($danhsach[$i]['TieuDe'] == $TieuDe)
            $isset++;
    }
    if($isset > 0)
        $Loi = true;
        
    $bs = new baivietbs();
    $bs->MaBaiViet = $MaBaiViet;
    $bs->TieuDe = $TieuDe;
    $bs->MaChuDe = $MaChuDe;
    $bs->MaNguoiDung = $_SESSION['MaNguoiDung'];
    $bs->TomTat = $TomTat;
    $bs->NoiDung = $NoiDung;
    $bs->NgayDang = date("Y-m-d H:i:s", time());//chuyendoi_nam_thang_ngay(date("d/m/Y"),"/","-");
    $bs->LuotXem = 0;
    $bs->KiemDuyet = 0;
    if($Loi == false)
    {
        $bs->Update();
        //header("location: index.php?do=danhsach_baiviet");
    }
    else
    {
        echo "Bài viết đã tồn tại!";
    }
?>